package com.jianhua.backend.utils;

import io.jsonwebtoken.*;
import java.util.Date;
import java.util.Map;

public class JwtUtil {

    // 密钥
    private static final String SECRET_KEY = "9f86d081884c7d659a2feaa0c55ad015";
    // 过期时间：24小时
    private static final long EXPIRATION = 86400000; // 毫秒

    /**
     * 生成JWT Token
     */
    public static String generateToken(Map<String, Object> claims) {
        return Jwts.builder()
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION))
                .signWith(SignatureAlgorithm.HS512, SECRET_KEY)
                .compact();
    }

    /**
     * 解析JWT Token获取内容
     */
    public static Map<String, Object> parseToken(String token) {
        return Jwts.parser()
                .setSigningKey(SECRET_KEY)
                .parseClaimsJws(token)
                .getBody();
    }
}
